﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据视图 V_PLM_CX_ProductSelect 对应的数据应用功能类。
	/// </summary>
	public class V_PLM_CX_ProductSelectApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IV_PLM_CX_ProductSelectRepository service = new V_PLM_CX_ProductSelectRepository();

        public List<V_PLM_CX_ProductSelectEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<V_PLM_CX_ProductSelectEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.TH.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public V_PLM_CX_ProductSelectEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public int ExecProductArrange(List<string> idArray) 
        {
            int result = 0;
            foreach (string id in idArray)
            {
                result += service.ExecSql(string.Format("exec  Pro_Plm_LJSC '{0}','{1}','{2}'", UseUnit, id, OperatorProvider.Provider.GetCurrent().UserName));
            }
            return result;
        }

    }
}